<%@ page import="com.xiaolin.utils.dbUtils" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="com.xiaolin.dao.impl.CartDaoImpl" %>
<%@ page import="javax.swing.text.Caret" %>
<%@ page import="com.xiaolin.bean.Cart" %>
<%@ page import="com.xiaolin.dao.impl.AllShoppDAOImol" %>
<%@ page import="com.xiaolin.bean.Shopp" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/1/6
  Time: 21:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    int num = Integer.parseInt(request.getParameter("num"));
    String user = request.getParameter("name");
    if (user.equals("null")){
        out.print("<h1>请先登录！</h1>");
    }
    else
    {
        String id = request.getParameter("id");
        Connection conn = dbUtils.getConnection();
        AllShoppDAOImol imol = new AllShoppDAOImol();
        Shopp shopp = imol.getShopp(conn, id);
        CartDaoImpl cartDao = new CartDaoImpl();
        Cart cart = new Cart(shopp.getId(),shopp.getName(),shopp.getPrice(),shopp.getType(),num,user);
        cartDao.insert(conn,cart);
        out.print("<h1>添加成功</h1>");
    }
    String url ="ShoppShown.jsp?num="+request.getParameter("a")+"&name="+user;
    response.setHeader("refresh", "1;url="+url);
%>
</body>
</html>
